package com.yswee.mallnavi.model.home;


import com.yswee.framework.data.BaseArrayData;
import com.yswee.framework.data.parser.IParser;
import com.yswee.framework.net.ITaskContext;
import com.yswee.framework.net.http.Callback;
import com.yswee.mallnavi.context.ApiConstant;
import com.yswee.mallnavi.context.ContextConstant;
import com.yswee.mallnavi.entity.home.NavEntity;
import com.yswee.mallnavi.model.BaseModel;
import com.yswee.mallnavi.parser.BaseListGsonParser;
import com.yswee.mallnavi.parser.VoidParser;

import org.json.JSONArray;

public class HomeModel extends BaseModel<Void> {

    public HomeModel(ITaskContext context) {
        super(context);
    }

    @Override
    protected IParser<Void> createParser() {
        return new VoidParser();
    }

    public void getNavs(final Callback<BaseArrayData<NavEntity>> c) {
        StringBuilder url = new StringBuilder();
        url.append(ApiConstant.API_NAVS).
            append("?type=").append(ContextConstant.getOrientationType());
        getData(url, new NavListParser(), c);
    }

    private class NavListParser extends BaseListGsonParser<NavEntity> {
        @Override
        public BaseArrayData<NavEntity> parseData(String json) {
            mIsOk = true;
            JSONArray ja = asJSONArray(json);
            return parseData(ja);
        }
    }

}
